import React from "react";
import type { FormViewProps, FieldBaseType, FieldType } from "./type";
import FormViewFactory from "./FormView";
import { extendField } from "./FormItem/render";
import hook from "./hook";

function instance<FIELD extends FieldBaseType>() {
  const view = (props: FormViewProps<FIELD>) => <FormViewFactory {...props} />;
  view.useFormView = (
    fields: (() => Array<FIELD>) | Array<FIELD>,
    deps?: Array<any>
  ) => hook(fields, deps);
  view.new = instance;
  view.extend = extendField;
  return view;
}

const FormView = instance<FieldType>();

export default FormView;
